#!/bin/sh
#desc: Download remote configuration

# Copyright(c) 2011 OpenDomo Services SL. Licensed under GPL v3 or later


/sbin/ifconfig eth0 | grep HWaddr | cut -c 39-55 | sed -e 's/://g' > /tmp/agent_uid
AUID=`cat /tmp/agent_uid`
URL="http://www.opendomo.com/getconfig.php?UID=$AUID"

case "$1" in
	stop)
		# nothing 
	;;
	reload|restart|start)
		# If there is no configuration available... 
		echo -n "Loading remote configuration ..."
		if test -f /mnt/odconf/sysconf/sysconf.tar.gz; then
			echo -n "(already configured)"
			exit 2
		else
			# ... try to download it!
			if wget $URL -O /tmp/cfgbackup.enc 2>/dev/null >/dev/null
			then
				exit 0
			else
				echo -n "(not found)"
				exit 2
			fi
		fi
	;;
	*)
		echo $"Usage: $0 {start|stop|restart|reload}"
		exit 1
esac
